import { native} from 'qvog-dsl';
import { AssignStmt, Variable } from 'qvog-types';
import { QHint } from '~/adapter/Defines';

export default native<QHint>({ name: '@test/exist-flow' })()
    .match((node: AssignStmt): node is AssignStmt => {
        return node.stream().any(s => s instanceof AssignStmt);
    })
    .when((node, { native }) => {
        const sinkNodes = native.api.nodes(s => {
            if (s instanceof AssignStmt) {
                let expr = s.target as Variable;
                return expr.name === 'b';
            }
            return false;
        }, 'Sink')
        return native.api.exists(node, '', sinkNodes, "Flow");
    })
    .report({ table: 'Flow' });